package cn.itcast.jsonParse;

import cn.itcast.beans.VehicleBean;
import org.json.JSONObject;

/**
 * @author lilulu
 * @date 2023-04-16 18:41
 */
public class JsonParseTest {

    public static void main(String[] args) {
        /**
         * 实现步骤：
         * 1）创建json字符串
         * 2）创建java类
         * 3）将使用org.json解析json字符串
         * 4）将json的字符串解析后为key：vaue，赋值给javaBean
         * 5）打印测试
         */
        String jsonStr1 = "{\"batteryAlarm\": 0, \"carMode\": 1,\"minVoltageBattery\": 3.89, \"chargeStatus\": 1,\"vin\": \"LS5A3CJC0JF890971\"}";
        JSONObject jsonObject = new JSONObject(jsonStr1);
        VehicleBean vehicleBean = new VehicleBean(
                jsonObject.getInt("batteryAlarm"),
                jsonObject.getInt("carMode"),
                jsonObject.getDouble("minVoltageBattery"),
                jsonObject.getInt("chargeStatus"),
                jsonObject.getString("vin")
        );
        System.out.println(vehicleBean);
    }


}
